<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-sys__dict">
      <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataList2()"
      >
        <el-form-item>
          <el-date-picker
            v-model="dataForm.startDate"
            type="date"
            placeholder="开始时间"
            value-format="yyyy-MM-dd"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-date-picker
            v-model="dataForm.endDate"
            type="date"
            placeholder="结束时间"
            value-format="yyyy-MM-dd"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button @click="query()">{{ $t("query") }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            v-if="$hasPermission('fishering:order:ewr')"
            @click="exportHandle()"
            >{{ $t("export") }}</el-button
          >
        </el-form-item>
      </el-form>

      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        border
        @selection-change="dataListSelectionChangeHandle"
        @sort-change="dataListSortChangeHandle"
        style="width: 100%"
      >
        <el-table-column
          prop="goodsName"
          label="商品名称"
          :show-overflow-tooltip="true"
          header-align="center"
          min-width="150"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="playDate"
          label="游玩日期"
          header-align="center"
          min-width="120"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="playTime"
          label="游玩时间"
          header-align="center"
          min-width="120"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="updateDate"
          label="核销时间"
          header-align="center"
          min-width="120"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="playLength"
          label="出游时间(小时)"
          header-align="center"
          min-width="120"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="realPrice"
          label="价格(元)"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          :label="$t('handle')"
          fixed="right"
          header-align="center"
          align="center"
          min-width="200"
        >
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click="lookDetail(scope.row.orderCode)"
              >详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle"
      >
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <!-- 详情 -->
      <detail ref="lookDetail" v-if="lookDetailVisible"> </detail>
    </div>
  </el-card>
</template>

<script>
var that;
import mixinViewModule from "@/mixins/view-module";
import detail from "./detail2";
export default {
  mixins: [mixinViewModule],

  data() {
    return {
      mixinViewModuleOptions: {
        createdIsNeed: false,
        getDataListURL: "/scenic/order/writeOffRecordPage",
        getDataListIsPage: true,
        exportURL: "/scenic/api/order/exportWriteOffRecord",
      },
      type: "",
      dataForm: {
        merchantId:
          this.$store.state.user.MerchantId ||
          localStorage.getItem("MerchantId"),
        startDate: "",
        endDate: "",
      },
    };
  },
  components: {
    detail,
  },
  created() {
    that = this;
    let year = new Date().getFullYear();
    let month = new Date().getMonth() + 1;
    let day = new Date().getDate();
    this.dataForm.startDate =
      year +
      "-" +
      (month < 10 ? "0" + month : month) +
      "-" +
      (day < 10 ? "0" + day : day);
    this.dataForm.endDate = this.dataForm.startDate;
    this.getDataList2();
  },
  methods: {
    getDataList2() {
      this.dataListLoading = true;
      this.$http
        .get(this.mixinViewModuleOptions.getDataListURL, {
          params: {
            homestayId: this.$store.state.user.homestayId,
            order: this.order,
            orderField: this.orderField,
            page: this.mixinViewModuleOptions.getDataListIsPage
              ? this.page
              : null,
            limit: this.mixinViewModuleOptions.getDataListIsPage
              ? this.limit
              : null,
            ...this.dataForm,
          },
        })
        .then(({ data: res }) => {
          this.dataListLoading = false;
          if (res.code !== 0) {
            this.dataList = [];
            this.total = 0;
            return this.$message.error(res.msg);
          }
          this.dataList = res.data.pageData.list;
          this.total = res.data.pageData.total;
        })
        .catch(() => {
          this.dataListLoading = false;
        });
    },
    query() {
      this.getDataList2();
    },
  },
};
</script>
